package com.lyw.gulimall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jdk.nashorn.internal.ir.CallNode;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyw.common.utils.PageUtils;
import com.lyw.common.utils.Query;

import com.lyw.gulimall.ware.dao.WareInfoDao;
import com.lyw.gulimall.ware.entity.WareInfoEntity;
import com.lyw.gulimall.ware.service.WareInfoService;


@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity> implements WareInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WareInfoEntity> page = this.page(
                new Query<WareInfoEntity>().getPage(params),
                new QueryWrapper<WareInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public IPage<Map<String, Object>> queryWareInfoPage(Integer page, Integer limit, String key) {
        Page<WareInfoEntity> result = new Page<>(page, limit);
        LambdaQueryWrapper<WareInfoEntity> lqw = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(key)) {
            lqw.and(wrapper -> {
                wrapper.eq(WareInfoEntity::getId, key)
                        .or().like(WareInfoEntity::getName, key)
                        .or().like(WareInfoEntity::getAddress, key);
            });
        }
        IPage<Map<String, Object>> pages = baseMapper.selectWareInfoPage(result, lqw);
        return pages;
    }

}